/**
 * @(#)ChannelApkInfoImpl.java 2016年9月22日
 * Copyright(C) 2015 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.dao.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.jsbd.boss.common.redis.RedisClient;
import org.jsbd.boss.dao.IChannelApkInfoDAO;
import org.jsbd.boss.domian.ChannelApkInfo;
import org.jsbd.boss.util.CacheKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.hziee.common.dbroute.BaseDAO;

/**
 * TODO 请加入本类的说明
 * 
 * @author <a href="mailto:zhangbinghua@zhexinit.com" >zbh</a>
 * @version 1.0.0
 */
public class ChannelApkInfoDAOImpl extends BaseDAO implements IChannelApkInfoDAO {
	public static final Logger LOGGER = LoggerFactory.getLogger(ChannelApkInfoDAOImpl.class);

	@Resource
	private RedisClient redisClient;
	@Override
	public Map<String, Object> selectConfigPageListMap(ChannelApkInfo form) {
		form = (form == null ? new ChannelApkInfo() : form);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", super.queryForCount("qy_channelapk_config.select_config_page_list_count", form));
		map.put("rows", super.queryForList("qy_channelapk_config.select_config_page_list", form));
		return map;
	}

	@Override
	public Integer insertConfig(ChannelApkInfo channelApkInfo) {
		return super.update("qy_channelapk_config.INSERT_CONFIG", channelApkInfo);
	}

	@Override
	public ChannelApkInfo getConfigByMark(String mark) {
		ChannelApkInfo configDO = (ChannelApkInfo) redisClient.get(CacheKey.CHANNEL_APK_INFO_KEY + mark);
		if (configDO == null) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("mark", mark);
			configDO = (ChannelApkInfo) super.queryForObject("qy_channelapk_config.GET_CONFIG_BY_MARK", params);
			if (configDO != null) {
				redisClient.put(CacheKey.CHANNEL_APK_INFO_KEY + mark, configDO, CacheKey.MEMCACHE_EXPIRY_TIME);
			}
		}
		return configDO;
	}

	@Override
	public ChannelApkInfo getConfigByMarkForPage(String mark) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("mark", mark);
		return (ChannelApkInfo) super.queryForObject("qy_channelapk_config.GET_CONFIG_BY_MARK", params);
	}

	@Override
	public Integer deleteConfig(String mark) {
		return super.update("qy_channelapk_config.DELETE_CONFIG", mark);
	}

	@Override
	public Integer updateProvinceByMark(String mark, String province) {
		redisClient.remove(CacheKey.CHANNEL_APK_INFO_KEY + mark);
		Map<String, String> params = new HashMap<String, String>();
		params.put("mark", mark);
		params.put("province", province);
		return super.update("qy_channelapk_config.UPDATE_PROVINCE_CHANNELAPK_BYMARK", params);
	}

}
